<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/21
 * Time: 9:47
 * 产品出库
 */

require('../include/init.inc.php');
$action = $id = $products_id = $model = $num = $pg = $due_status = '';
extract($_REQUEST, EXTR_IF_EXISTS);

$product = array();
if ($action == 'modify_ck') {
    $product = AdminProducts::getProductById($id);
}

if (Common::isPost()) {
    $product = AdminProducts::getProductByModel($model);

    if (!$product) {
        Common::exitWithError(ErrorMessage::PRODUCT_NO_EXISTS, "entpot/products_due.php");

    }

    if (!$num || intval($num) > $product['products_sale_num']) {
        Common::exitWithError(ErrorMessage::SALE_THAN_OTHER, "entpot/products_due.php");
    }

    if ($model && $products_id) {
        $data = array("products_evaluate" => $pg, "products_sale_other" => $num + $product['products_sale_other'], "products_due_date" => date('Y-m-d H:i:s'), "products_due_status" => $due_status);
        $result = AdminProducts::update($products_id, $data);


        if ($result) {
            SysLog::addLog(UserSession::getUserName(), 'Update', 'ProductsUpdate', $name, json_encode($data));
            Common::exitWithSuccess('出库完成', 'entpot/products.php');
        } else {
            OSAdmin::alert("error");
        }
    }
}


$modelOptions = AdminProducts::getModelForOptions();
Template::assign('modelOptions', json_encode($modelOptions));

$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::assign('_GET', $product);
Template::display('entpot/products_due.tpl');